package cn.shangtour.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.shangtour.common.pojo.User;
import cn.shangtour.common.vo.SysResult;
import cn.shangtour.user.service.UserService;

@RestController
@RequestMapping("/user")
public class UserController {

	@Autowired
	private UserService userService;
	@RequestMapping("/checkUserName")
	public SysResult checkUsername(String passport){
		Integer exist=userService.checkUsername(passport);
		if(exist==0){
			return SysResult.ok();
		}else{
			return SysResult.build(201, "已存在", null);
			
		}
	}
	
	@RequestMapping("/save")
	public SysResult userSave(User user){
		try {
			userService.userSave(user);
			return SysResult.ok();
		} catch (Exception e) {
			e.printStackTrace();
			return SysResult.build(201, "", null);
		}
	}
	
	@RequestMapping("password")
	public SysResult setPassword(User user){
		
		try {
			userService.setPassword(user);
			return SysResult.ok();
		} catch (Exception e) {
			e.printStackTrace();
			return SysResult.build(201, "", null);
		}
	}
	
	
	
	
	
}
